package com.example.demo.service;

import com.example.demo.entity.Grade;
import com.example.demo.repository.GradeRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
import org.springframework.transaction.annotation.Transactional;

@Service
@Transactional
public class GradeService {
    @Autowired
    private GradeRepository gradeRepository;
    
    public List<Grade> findAll() {
        List<Grade> grades = gradeRepository.findAll();
        grades.forEach(grade -> {
            grade.getStudent().getName();
            grade.getCourse().getName();
        });
        return grades;
    }
    
    public List<Grade> findByCourseId(Long courseId) {
        return gradeRepository.findByCourseId(courseId);
    }
    
    public Grade save(Grade grade) {
        return gradeRepository.save(grade);
    }
    
    public List<Grade> findByScoreRange(Double minScore, Double maxScore) {
        return gradeRepository.findByScoreRange(minScore, maxScore);
    }
} 